import React, {useContext} from 'react';
import styles from './Robot.module.css'
import {appContext} from '../AppState'
import { useAddToCart} from './AddToCart'
interface RobotProps {
    id: number;
    name: string;
    email: string;
}
const RobotDiscount: React.FC<RobotProps> = ({ id, name, email }) => {
    const value = useContext(appContext)
    const addToCart = useAddToCart()
    return  (
        <div className={styles.cardContainer}>
            <img src={`https://robohash.org/${id}}`} alt="robot" />
            <p>半价优惠</p>
            <h2>{name}</h2>
            <p>{email}</p>
            <div>{value.username}</div>
            <button onClick={()=>{addToCart(id, name)}}>加入购物车</button>
        </div>
    );
};
export default RobotDiscount;